<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH . 'controllers/admin.php';

/**
 * Контроллер просмотра и изменения SAPE настроек
 *
 * @package CoreFramework
 * @version 1.0
 * @author Gennadiy Kozlenko
 */
class Admin_Sape_Settings extends Admin {
   
   /**
    * Конструктор класса
    *
    * @access public
    * @return Admin_Sape_Settings
    */
   function Admin_Sape_Settings() {
      parent::Admin();
      $this->set_menu(5, 2);
   } // end Admin_Sape_Settings
   
   /**
    * Метод по умолчанию
    *
    * @access public
    */
   function index() {
      $data = array();
      // Стандартные поля
      $use_sape = $this->variables->get('use_sape');
      $use_sape_context = $this->variables->get('use_sape_context');
      $sape_user = $this->variables->get('sape_user');
      // Валидируем и, если нужно, изменяем
      if (false !== $this->input->post('edit')) {
         // Получаем из поста поля
         $use_sape = (bool) $this->input->post('use_sape');
         $use_sape_context = (bool) $this->input->post('use_sape_context');
         $sape_user = trim($this->input->post('sape_user'));
         // Сохраняем
         $this->variables->set('use_sape', $use_sape ? 'yes' : 'no');
         $this->variables->set('use_sape_context', $use_sape_context ? 'yes' : 'no');
         $this->variables->set('sape_user', $sape_user);
         $this->set_message($this->lang->line('edit_settings_succ'), 'info', true);
         $this->redirect($this->get_controller());
      }
      // Забиваем в дату поля
      $this->load->helper('element');
      $data['use_sape'] = create_checkbox('use_sape', 'yes' == $use_sape);
      $data['use_sape_context'] = create_checkbox('use_sape_context', 'yes' == $use_sape_context);
      $data['sape_user'] = htmlspecialchars($sape_user);
      // Выводим
      $this->set_content($this->parser->parse('admin/sape_settings.html', $data, true));
      $this->display();
   } // end index
   
}
